<?php

require_once( dirname(__FILE__).'/../libs/bedmintonlib.php' );

if (! isset( $_GET[ 'galleryId' ] ))
    exit;

$galleryId = $_GET[ 'galleryId' ];


$db = Db::db();
$dbConnection = $db->connection();
if (is_null( $dbConnection ))
{
    echo( $db->getErrorStr() );
    exit;
}

try
{
    $statement = $dbConnection->prepare( "SELECT id, imagepreviewpath, imagepath, description, comment FROM galleryimages WHERE galleryid = ?" );
    $statement->bindParam( 1, $galleryId );
    $statement->execute();
    $result = $statement->fetchAll( PDO::FETCH_NUM );
    if (! $result)
        exit;
    
    $i = 0;
    $j = 0;
    $resultStr = "<div class=\"gallerytableholder\"><table class = \"gallerydetailstable\">";
    foreach($result as $row)
    {
        if ($i == 4)
            $i = 0;

        if ($i == 0)
            $resultStr .= "<tr>";

        $resultStr .= "<td id =\"imagetd" . $row[ 0 ] . "\" class =\"image\">" . 
            "<a title=\"$row[4]\" class=\"fancybox\" rel=\"group$j\" href=\"../galleryimages/$row[2]\">" . 
            "<img src=\"../galleryimages/$row[1]\" alt=\"\" />" . 
            "</a>" . $row[ 3 ] . "</td>";

        if ($i == 3)
            $resultStr .= "</tr>";

        $i ++;
        $j ++;
    }
    
    $resultStr .= "</table></div>";
}
catch(PDOException $e)
{
    echo( $e->getMessage() );
    exit;
}

$javascriptStr = "
<script type=\"text/javascript\">
    $(document).ready(function() {
		$(\".fancybox\").fancybox
        ({
            helpers:
            {
                title :
                {
	                 type : 'inside' // 'float', 'inside', 'outside' or 'over'
                }
            }
        });
	});

</script>";

$resultStr .= $javascriptStr;
echo( $resultStr );

?>


